home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / strpp300.zip / PARSESTR.CPP < prev    next >
C/C++ Source or Header  |  1993-04-11  |  4KB  |  174 lines

  1. /* -------------------------------------------------------------------- */
  2. /* String++ Version 3.00                                       04/10/93 */
  3. /*                                                                      */
  4. /* Enhanced string class for Turbo C++/Borland C++.                     */
  5. /* Copyright 1991-1993 by Carl W. Moreland                              */
  6. /*                                                                      */
  7. /* parsestr.cpp                                                         */
  8. /* -------------------------------------------------------------------- */
  9.  
  10. #include "parsestr.h"
  11.  
  12. /* ----- Constructors/Destructors ------------------------------------- */
  13.  
  14. ParseString::ParseString(): String()
  15. {
  16.   offset = 0;
  17. }
  18.  
  19. ParseString::ParseString(const char* p): String(p)
  20. {
  21.   offset = 0;
  22. }
  23.  
  24. ParseString::ParseString(const string& s): String(s)
  25. {
  26.   offset = 0;
  27. }
  28.  
  29. ParseString::~ParseString(void)
  30. {
  31.   Reset();
  32. }
  33.  
  34. /* ----- SetStr/AddStr ------------------------------------------------ */
  35.  
  36. void ParseString::SetStr(const char* p)
  37. {
  38.   Reset();                // reset the string
  39.   String::SetStr(p);
  40. }
  41.  
  42. void ParseString::SetStr(const string& s)
  43. {
  44.   Reset();                // reset the string
  45.   String::SetStr(s);
  46. }
  47.  
  48. void ParseString::AddStr(const char c)
  49. {
  50.   unsigned n = offset;            // save the offset
  51.   Reset();                // reset the string
  52.   String::AddStr(c);            // add new contents
  53.  
  54.   operator+=(n);            // reapply the offset
  55. }
  56.  
  57. void ParseString::AddStr(const char* p)
  58. {
  59.   unsigned n = offset;            // save the offset
  60.   Reset();                // reset the string
  61.   String::AddStr(p);            // add new contents
  62.  
  63.   operator+=(n);            // reapply the offset
  64. }
  65.  
  66. void ParseString::AddStr(const string& s)
  67. {
  68.   unsigned n = offset;            // save the offset
  69.   Reset();                // reset the string
  70.   String::AddStr(s);            // add new contents
  71.  
  72.   operator+=(n);            // reapply the offset
  73. }
  74.  
  75. void ParseString::Reset(void)
  76. {
  77.   strPtr -= offset;            // reset strPtr to zero position
  78.   strLen += offset;            // reset strLen
  79.   offset = 0;
  80. }
  81.  
  82. const char* ParseString::Offset(unsigned n)
  83. {
  84.   if(strLen >= n-offset)
  85.   {
  86.     strPtr -= offset;            // reset strPtr to zero position
  87.     strLen += offset;            // reset strLen
  88.     offset  = n;            // new absolute offset
  89.     strPtr += n;            // increment strPtr
  90.     strLen -= n;            // set strLen
  91.   }
  92.   return strPtr;
  93. }
  94.  
  95. /* ----- Operators ---------------------------------------------------- */
  96.  
  97. String& ParseString::operator=(const char* p)
  98. {
  99.   SetStr(p);
  100.   return *this;
  101. }
  102.  
  103. String& ParseString::operator=(const String& s)
  104. {
  105.   SetStr(s);
  106.   return *this;
  107. }
  108.  
  109. const char* ParseString::operator++()
  110. {
  111.   if(strLen > 0)
  112.   {
  113.     ++offset;
  114.     ++strPtr;
  115.     --strLen;
  116.   }
  117.   return strPtr;
  118. }
  119.  
  120. const char* ParseString::operator++(int)
  121. {
  122.   if(strLen > 0)
  123.   {
  124.     offset++;
  125.     strPtr++;
  126.     strLen--;
  127.   }
  128.   return strPtr;
  129. }
  130.  
  131. const char* ParseString::operator--()
  132. {
  133.   if(offset > 0)
  134.   {
  135.     --offset;
  136.     --strPtr;
  137.     ++strLen;
  138.   }
  139.   return strPtr;
  140. }
  141.  
  142. const char* ParseString::operator--(int)
  143. {
  144.   if(offset > 0)
  145.   {
  146.     offset--;
  147.     strPtr--;
  148.     strLen++;
  149.   }
  150.   return strPtr;
  151. }
  152.  
  153. const char* ParseString::operator+=(const unsigned n)
  154. {
  155.   if(strLen >= n)
  156.   {
  157.     offset += n;
  158.     strPtr += n;
  159.     strLen -= n;
  160.   }
  161.   return strPtr;
  162. }
  163.  
  164. const char* ParseString::operator-=(const unsigned n)
  165. {
  166.   if(offset >= n)
  167.   {
  168.     offset -= n;
  169.     strPtr -= n;
  170.     strLen += n;
  171.   }
  172.   return strPtr;
  173. }
  174.